<?php
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Response as FacadesResponse;
use Tymon\JWTAuth\Facades\JWTAuth;
use Illuminate\Support\Facades\Session;



class AreaController extends BaseController {
            /**
             * 返回省份列表
             */
            public function provinceList() {
                $provinces = AreaHelper::getProvinceList();
                return $this->makeView('helper.area', $provinces);
            }

            /**
             * 返回城市列表
             */
            public function cityList($provinceId) {
                $provinces = AreaHelper::getProvinceList();
                if (!AreaHelper::areaKeyExists($provinceId, $provinces)) {
                    return FacadesResponse::json (
                        array (
                                "status_code" => 404, 
                        ), 404 );
                }
                $cities = AreaHelper::getCityList($provinceId);
                return $this->makeView('helper.area', $cities);
            }

            /**
             * 返回区域列表
             */
            public function districtList($cityId) {
                $provinceId = substr($cityId, 0, 2) . '0000';
                $provinces = AreaHelper::getProvinceList();
                $cities = AreaHelper::getCityList($provinceId);
                if (!AreaHelper::areaKeyExists($provinceId, $provinces) || !AreaHelper::areaKeyExists($cityId, $cities)) {
                    return FacadesResponse::json (
                        array (
                                "status_code" => 404, 
                        ), 404 );
                }

                $districts = AreaHelper::getDistrictList($cityId);
                return $this->makeView('helper.area', $districts);
            }
            
            /**
             * 省份根据首字母排序
             */
            public function provinceLetters(){
                $provinces = AreaHelper::getProvinceLetter();
                return $this->makeView('helper.area', $provinces);
                
    }
            public function addressCode($lat, $lng)
            {
                $result = UtilsHelper::get_client_city_info_by_latlng($lat, $lng);
                Session::put('latlng',"$lat,$lng");
                return $this->makeView('helper.area', $result);
            }




}